package one.stand.service.impl;

import one.stand.model.ResultModel;
import one.stand.model.SunCodeModel;
import one.stand.request.SunCodeRequest;
import one.stand.response.SunCodeResponse;
import one.stand.service.BaseService;
import one.stand.service.SunCodeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: ZRH
 * @CreateDate: 2019/6/19 9:39
 */
@Service
@Transactional
public class SunCodeServiceImpl extends BaseService implements SunCodeService {


    @Override
    public ResultModel<SunCodeResponse> getSunCode(SunCodeRequest request) {
        if(request == null || request.getSunCodeId() == null){
            return ResultModel.checkParamFail("sunCodeId: 太阳码Id为空");
        }
        SunCodeModel model = sunCodeMapper.selectByPrimaryKey(request.getSunCodeId());
        if(model == null){
            return ResultModel.fail(String.format("无法找到对应的太阳码记录(%s)", request.getSunCodeId()));
        }
        SunCodeResponse response = new SunCodeResponse();
        BeanUtils.copyProperties(model, response);
        return ResultModel.success(response);
    }

}
